package com.zjp.demo02251.handler;

import com.zjp.demo02251.dao.Result;
import com.zjp.demo02251.exception.CompanyUserExcption;
import com.zjp.demo02251.utils.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * @Description:
 * @author james
 * @date 2018/2/28  20:20
*/
@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e){
        if (e instanceof CompanyUserExcption) {
            CompanyUserExcption companyUserExcption = (CompanyUserExcption) e;
            return ResultUtil.error(companyUserExcption.getCode(),e.getMessage());
        }
       return ResultUtil.error(-1,"服务器异常");
    }

}
